package com.axjy.gateway;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Component
@Slf4j
public class TaoPiaopiaoFilter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
       String uri=  exchange.getRequest().getURI().getPath();
        log.debug("预处理:"+uri);
        long before=System.currentTimeMillis();

        Mono<Void> mono= chain.filter(exchange)
        .then(Mono.fromRunnable(()->{
            log.debug("后处理："+(System.currentTimeMillis()-before));
        }));


        return mono;
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
